package com.backedserver.controller.standvalue;

import com.common.base.BindCreateBy;
import com.common.base.BindUpdateBy;
import com.common.requestvo.standvalue.StandValueReqVo;
import com.common.service.standvalue.StandValueService;
import com.common.utils.PageUtil;
import com.common.utils.ResultVoUtil;
import com.common.vo.PageVo;
import com.common.vo.ResultVo;
import com.common.vo.standvalue.StandValueVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * 指标导入Controller
 *
 * @author johnny
 * @create 2021-05-15 8:17 上午
 **/

@Api(tags = "标准值模块")
@RestController
@RequestMapping("/stand_value")
@Slf4j
public class StandValueController {


    private final StandValueService standValueService;

    public StandValueController(StandValueService standValueService) {
        this.standValueService = standValueService;
    }


    @GetMapping("/listByCondition")
    @ApiOperation(value = "根据条件查询标准值信息 (分页)")
    public ResultVo listByCondition(StandValueReqVo standValueReqVo,
                                    PageVo pageVo) {
        pageVo.setPageNumber(pageVo.getPageNumber() - 1);
        Page<StandValueVo> page = standValueService.listByCondition(standValueReqVo, PageUtil.initPage(pageVo));
        return ResultVoUtil.success(page);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增标准值信息")
    @BindCreateBy
    public ResultVo add(@RequestBody StandValueReqVo standValueReqVo) {
        standValueService.add(standValueReqVo);
        return ResultVoUtil.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改标准值信息")
    @BindUpdateBy
    public ResultVo edit(@RequestBody StandValueReqVo standValueReqVo) {
        standValueService.edit(standValueReqVo);
        return ResultVoUtil.success();
    }

    /**
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除考标准值信息")
    @ApiImplicitParam(name = "id", value = "评价id", dataType = "Long", example = "1")
    public ResultVo delete(@PathVariable Long id) {
        standValueService.delete(id);
        return ResultVoUtil.success();
    }

}